package com.sdkteam.Database;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.sdkteam.Ailatrieuphu.R;
import com.sdkteam.Ailatrieuphu.SMSSender;
import com.sdkteam.MainMenu.MenuActivity;

public class UpdateDialog extends Dialog implements
		android.view.View.OnClickListener {
	Button ok, cancel;
	TextView message,title;
	MenuActivity activity;

	public UpdateDialog(Context context, MenuActivity activity) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.update_dialog);
		
		this.activity = activity;
		
		ok = (Button) findViewById(R.id.update_ok);
		cancel = (Button) findViewById(R.id.update_no);
		message = (TextView) findViewById(R.id.update_message);
		title = (TextView)findViewById(R.id.Title);
		
		message.setText("Gửi tin nhắn tới 8591 để cập nhật" + "\n"
				+ "Cước phí: 5.000đ/tin");
		ok.setOnClickListener(this);
		cancel.setOnClickListener(this);

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.update_ok:
			activity.enableButton();
			try {
//				Toast.makeText(getContext(), "Sendding SMS...", Toast.LENGTH_LONG).show();
				SMSSender sms = new  SMSSender();
				sms.sendSMS("8591", "SDKTEAM AILATRIEUPHU UPDATE", activity); 
				dismiss();
			} catch (Exception e) {
				// TODO: handle exception
				Toast.makeText(getContext(), "Kiểm tra lại tài khoản của bạn", Toast.LENGTH_LONG).show();
				dismiss();
			}

			break;

		case R.id.update_no:
			activity.enableButton();
			dismiss();
			break;
		}

	}

}
